//
//  MTNavigationController.m
//  DSJY
//
//  Created by 冯华强 on 15/10/16.
//  Copyright (c) 2015年 HQ. All rights reserved.
//  公共的导航栏

#import "MTNavigationController.h"
#import "MTConst.h"

@interface MTNavigationController ()

@end

@implementation MTNavigationController

+ (void)initialize
{
    //设置导航栏背景
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    [navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_navigationBar_normal"] forBarMetrics:UIBarMetricsDefault];
    
    //设置barButtonItem的样式
    UIBarButtonItem *barButtonItem = [UIBarButtonItem appearance];
    NSMutableDictionary *attrDict = [NSMutableDictionary dictionary];
    attrDict[NSForegroundColorAttributeName] = @"";
    [barButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:MTColor(21, 188, 173)} forState:UIControlStateNormal];
    [barButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateDisabled];
}

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
    if (self = [super initWithRootViewController:rootViewController]) {
        self.autorotate = YES;
    }
    return self;
}

#pragma mark - 禁止自动旋转固定竖屏
- (BOOL)shouldAutorotate
{
    return self.isAutorotate ? YES : NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return self.isAutorotate ? UIInterfaceOrientationMaskAll : (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return self.isAutorotate ? YES : (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

@end
